<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello World</title>
  <script src="https://unpkg.com/vue"></script>

</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      1. 子组件实现多个双向数据绑定 
      - v-model:数据1=""
      - v-model:数据2=""
      2. modelModifiers 自定义修饰符
    */

    const app = Vue.createApp({
      data() {
        return {
          count: 'a'
        }
      },
      template: `<div>
        <counter v-model.uppercase="count"/>
      </div>`
    })
    app.component('counter', {
      props: {
        'modelValue': String,
        'modelModifiers': {
          default: () => ({})
        }
      },
      template: `<div>
                  数据1：{{modelValue}}
                  <button @click="handleClick">自增</button>
                </div>`,
      methods: {
        handleClick() {
          let newValue = this.modelValue + 'b';
          if(this.modelModifiers.uppercase){
            newValue = newValue.toUpperCase()
          }
          this.$emit('update:modelValue', newValue)
        }
      }
    })
    const vm = app.mount('#root');
  </script>
</body>

</html>